﻿//文件指定编译编码UTF-8
#pragma execution_character_set("utf-8")

/**
*    @file:    mainwindow.cpp
*    @brief:
*    @author:  sanshi522@163.com
*    @date:    2024-11-28  14:38
*/

#include "audioconverter.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QFileDialog>
#include <QThread>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_disposeBtn_clicked()
{
    if(ui->inPathLineEdit->text().isEmpty() || ui->outPathLineEdit->text().isEmpty()){
        qDebug() << "文件不要可为空!";
        return;
    }
    bool success;
    for (int i=0;i<1;i++) {
        AudioConverter *converter = new AudioConverter();
        success = converter->convertToWav(ui->inPathLineEdit->text(), ui->outPathLineEdit->text());
        converter->deleteLater();
        QThread::msleep(1);
    }
    if (success) {
        qDebug() << "Conversion successful!";
    } else {
        qDebug() << "Conversion failed!";
    }
}

void MainWindow::on_inPathSelectBtn_clicked()
{
    QString path = QFileDialog::getOpenFileName(this,"选择输入文件","");
    if(!path.isEmpty()){
        ui->inPathLineEdit->setText(path);
    }
}

void MainWindow::on_outPathSelectBtn_clicked()
{
    QString path = QFileDialog::getSaveFileName(this,"选择输出文件","");
    if(!path.isEmpty()){
        ui->outPathLineEdit->setText(path);
    }
}
